export function getHandleTypeOptions() {
	return [{
			label: "上报社区村",
			value: "community"
		},
		{
			label: "上报镇街",
			value: "streetCenter1"
		},
		{
			label: "自办",
			value: "01"
		}
	];
}

export function getBuildingTypeOptions() {
	return [{
			label: "楼房",
			value: "1"
		},
		{
			label: "平房",
			value: "2"
		},
		{
			label: "别墅",
			value: "3"
		},
		{
			label: "工厂",
			value: "4"
		}
	]
}

export function getYesNoOptions() {
	return [{
			label: "是",
			value: "Y"
		},
		{
			label: "否",
			value: "N"
		}
	]
}

export function getYesNoNumberOptions() {
	return [{
			label: "是",
			value: 1
		},
		{
			label: "否",
			value: 0
		}
	]
}

export function getYesNoNumberStringOptions() {
	return [{
			label: "是",
			value: "1"
		}, {
			label: "否",
			value: "0"
		},

	];
}

export function getboxStatusOptions() {
	return [{
			label: "未答复",
			value: 0
		},
		{
			label: "已答复",
			value: 1
		}
	];
}
export function getMonthsOptions() {
	const monthsArray = [];
	for (let i = 1; i <= 12; i++) {
		const month = {
			label: `${i}月`,
			value: i+""
		};
		monthsArray.push(month);
	}
	return monthsArray
}

export function getHouseName(data) {
	let name, houseTypeName;
	if (data.houseType == 1) {
		name = data.communityName + data.buildingNo + data.buildingUnit + "-" + data.houseNumber
	} else {
		name = data.communityName + data.houseNumber
	}
	if (data.houseTypeName) {
		houseTypeName = data.houseTypeName
	} else {
		houseTypeName = getHouseTypeName(data.houseType)
	}
	return `[${houseTypeName}]` + name

}
export function getHouseTypeName(type) {
	let name;
	let buildingTypeOptions = getBuildingTypeOptions()
	let buildingType = buildingTypeOptions.find((item) => item.value == type)
	return buildingType.label
}

export function getSmallTimeAll(timestamp){
	// 计算当前时间
	let currentDate = new Date(timestamp*1000);
	let currentYear = currentDate.getFullYear();
	let currentMonth = currentDate.getMonth() + 1;
	let currentDay = currentDate.getDate();
	let currentHours = currentDate.getHours();
	let currentMinutes = currentDate.getMinutes();
	let currentSeconds = currentDate.getSeconds();
	
	return `${currentYear}${addZero(currentMonth)}${addZero(currentDay)}${addZero(currentHours)}${addZero(currentMinutes)}${addZero(currentSeconds)}`;
}

export function getSmallTime(timestamp){
	// 计算当前时间
	let currentDate = new Date(timestamp*1000);
	let currentYear = currentDate.getFullYear();
	let currentMonth = currentDate.getMonth() + 1;
	let currentDay = currentDate.getDate();
	let currentHours = currentDate.getHours();
	let currentMinutes = currentDate.getMinutes();
	let currentSeconds = currentDate.getSeconds();
	
	return `${currentYear}${addZero(currentMonth)}${addZero(currentDay)}${addZero(currentHours)}${addZero(currentMinutes)}`;
}

export function getTimeFormat(timestamp){
    if(timestamp == '' || timestamp == null || timestamp == undefined){
        timestamp = new Date().getTime();
    }
	// 计算当前时间
	let currentDate = new Date(timestamp*1000);
	let currentYear = currentDate.getFullYear();
	let currentMonth = currentDate.getMonth() + 1;
	let currentDay = currentDate.getDate();
	let currentHours = currentDate.getHours();
	let currentMinutes = currentDate.getMinutes();
	let currentSeconds = currentDate.getSeconds();
	
	return `${currentYear}-${addZero(currentMonth)}-${addZero(currentDay)} ${addZero(currentHours)}:${addZero(currentMinutes)}:${addZero(currentSeconds)}`;
}

//获取当前时间
export function getTime(){
	// 计算当前时间
	let currentDate = new Date();
	let currentYear = currentDate.getFullYear();
	let currentMonth = currentDate.getMonth() + 1;
	let currentDay = currentDate.getDate();
	let currentHours = currentDate.getHours();
	let currentMinutes = currentDate.getMinutes();
	let currentSeconds = currentDate.getSeconds();
	
	return `${currentYear}-${addZero(currentMonth)}-${addZero(currentDay)} ${addZero(currentHours)}:${addZero(currentMinutes)}:${addZero(currentSeconds)}`;
}
			
export function addZero(num) {
	if(num < 10){
		num = `0${num}`;
	}
	return num;
}

export function getYmd(){
	// 计算当前时间
	let currentDate = new Date();
	let currentYear = currentDate.getFullYear();
	let currentMonth = currentDate.getMonth() + 1;
	let currentDay = currentDate.getDate();
	
	return `${currentYear}-${addZero(currentMonth)}-${addZero(currentDay)}`;
}

export function getDayStr() {
  var y, m, d, h, mm, s;
  var date = new Date();
  y = date.getFullYear();
  m = date.getMonth() + 1;
  d = date.getDate();
  m = m < 10 ? '0' + m : m;
  d = d < 10 ? '0' + d : d;
  // //console.log('日期:',y,m,d)
  // return '20220607' // 生成指定日期
  return '' + y + m + d;
}

//计算两个时间差
export function GetDateDiff(startTime, endTime, diffType) {
    //将xxxx-xx-xx的时间格式，转换为 xxxx/xx/xx的格式 
    startTime = startTime.replace(/\-/g, "/");
    endTime = endTime.replace(/\-/g, "/");
    //将计算间隔类性字符转换为小写
    diffType = diffType.toLowerCase();
    var sTime =new Date(startTime); //开始时间
    var eTime =new Date(endTime); //结束时间
    //作为除数的数字
    var timeType =1;
    switch (diffType) {
        case"second":
            timeType =1000;
        break;
        case"minute":
            timeType =1000*60;
        break;
        case"hour":
            timeType =1000*3600;
        break;
        case"day":
            timeType =1000*3600*24;
        break;
        default:
        break;
    }
    return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(timeType));
}

//手机号码，座机号码4位加空格
export function addSpaceToPhoneNumber(phoneNumber) {
    return phoneNumber.replace(/(\d{4})(?=\d)/g, '$1 ');
}

export function addSpaceToPhone(phoneNumber) {
    return phoneNumber.replace(/\D/g, '').replace(/....(?!$)/g, '$& ');
}

/**
 * 获取时分秒
 * @param {Number} seconds 总秒数
 * @param {String} dateFormat 返回的日期格式，默认为'H:i:s'
 */
export function getHms(seconds, dateFormat = 'H:i:s'){
  var obj = {};
  obj.H = Number.parseInt(seconds / 3600);
  obj.i = Number.parseInt((seconds - obj.H * 3600) / 60);
  obj.s = Number.parseInt(seconds - obj.H * 3600 - obj.i * 60);
  if (obj.H < 10) {
    obj.H = '0' + obj.H;
  }
  if (obj.i < 10) {
    obj.i = '0' + obj.i;
  }
  if (obj.s < 10) {
    obj.s = '0' + obj.s;
  }
 
  // 3.解析
  var rs = dateFormat.replace('H', obj.H).replace('i', obj.i).replace('s', obj.s);
  return rs;
}

export function convertToUnixWithAddedSeconds(timeStr,addTime) {
  // 处理格式：将空格替换为 'T' 创建 ISO 格式
  const isoTime = timeStr.replace(' ', 'T');
  
  // 创建 Date 对象（自动处理本地时区）
  const date = new Date(isoTime);
  
  // 验证时间是否有效
  if (isNaN(date.getTime())) {
    throw new Error('无效的时间格式，请使用 "YYYY-MM-DD HH:mm:ss" 格式');
  }
  
  // 2. 转换为 Unix 时间戳（毫秒），然后加 10 秒（10000 毫秒）
  const unixTimeMs = date.getTime() + addTime;
  
  // 3. 转换为秒级 Unix 时间戳
  //return Math.floor(unixTimeMs / 1000);
  return unixTimeMs;
}